package com.ruoyi.cs.event.followRecord.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.cs.event.followRecord.domain.FollowRecord;
import com.ruoyi.cs.event.followRecord.domain.FollowRecordCond;
import com.ruoyi.cs.event.followRecord.service.IFollowRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
/**
 * 跟进记录
 */
@RestController
@RequestMapping("/cs/follow")
@Api(value = "跟进记录模块", tags = "跟进记录接口")
public class FollowRecordController extends BaseController {
    @Autowired
    private IFollowRecordService followRecordService;
    /**
     * 获取跟进记录
     * @param cond
     * @return
     */
    @ApiOperation(value = "获取跟进记录",notes = "查询所有跟进记录信息")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody FollowRecordCond cond){
        startPage();
        List<FollowRecord> followRecordList = followRecordService.selectFollowRecordList(cond);
        return getDataTable(followRecordList);
    }

    /**
     * 导出跟进记录
     * @param cond
     * @return
     */
    @ApiOperation(value = "导出跟进记录",notes = "导出跟进记录")
    @PostMapping("/export")
    public AjaxResult export(@RequestBody FollowRecordCond cond)
    {
        List<FollowRecord> followRecordList = followRecordService.selectFollowRecordList(cond);
        ExcelUtil<FollowRecord> util = new ExcelUtil<>(FollowRecord.class);
        return util.exportExcel(followRecordList, "跟进记录数据");
    }

    /**
     * 新增跟进记录
     * @param followRecord
     * @return
     */
    @ApiOperation("新增跟进记录")
    @ApiImplicitParam(name = "followRecord", value = "新增客跟进记录", dataType = "FollowRecord")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody FollowRecord followRecord){

        return toAjax(followRecordService.insertFollowRecord(followRecord));
    }

    /**
     * 修改跟进记录
     * @param followRecord
     * @return
     */
    @ApiOperation("修改跟进记录")
    @ApiImplicitParam(name = "followRecord", value = "修改跟进记录", dataType = "FollowRecord")
    @PostMapping("/edit")
    public AjaxResult edit(@Validated @RequestBody FollowRecord followRecord)
    {
        return toAjax(followRecordService.updateFollowRecord(followRecord));
    }

    /**
     * 删除跟进记录
     * 仅修改删除标志位
     * @param followRecord
     * @return
     */
    @ApiOperation("删除跟进记录")
    @PostMapping("/delete")
    public AjaxResult delete(@RequestBody FollowRecord followRecord)
    {

        return toAjax(followRecordService.updateFollowRecordDeleteFlag(followRecord));
    }
}
